import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'

Vue.config.productionTip = false


//ElementUi组件
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
Vue.use(ElementUI);

import {Message} from "element-ui";

import 'font-awesome/css/font-awesome.min.css'

import {getRequest} from "./utils/api";
import {postRequest} from "./utils/api";
import {postKeyValueRequest} from "./utils/api";
import {putRequest} from "./utils/api";
import {deleteRequest} from "./utils/api";

Vue.prototype.$getRequest = getRequest;
Vue.prototype.$postRequest = postRequest;
Vue.prototype.$postKeyValueRequest = postKeyValueRequest;
Vue.prototype.$putRequest = putRequest;
Vue.prototype.$deleteRequest = deleteRequest;

import {initMenu} from "@/utils/menu";
//路由导航守卫
router.beforeEach((to,from,next) =>{
  if (to.path == '/') {
    document.body.style.background = '#fff';
    next();
  }else{
    let user = window.sessionStorage.getItem('loginer');
    if (user == null) {
      Message.warning('请先登录');
      next('/');
    }else{
      //查询用户能看的菜单，放到vuex中
      initMenu(router,store);
      next();
    }
  }
})

new Vue({
  router,
  store,

  render: h => h(App)
}).$mount('#app')
